package duhosdebuggolok;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class AntPainter implements Painter{
	
	private static BufferedImage antImage0 = null;
	private static BufferedImage antImage1 = null;
	private static BufferedImage antImage2 = null;
	private static BufferedImage antImage3 = null;
	private static BufferedImage antImage4 = null;
	private static BufferedImage antImage5 = null;
	
	private Ant ant;
	
	public AntPainter(Ant a){
		ant = a;
		if (antImage0 == null)
			loadImage();
	}
	
	private static void loadImage() {
		try {
			antImage0 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangya0.png"));
			antImage1 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangya1.png"));
			antImage2 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangya2.png"));
			antImage3 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangya3.png"));
			antImage4 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangya4.png"));
			antImage5 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangya5.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public boolean paint(Graphics2D g){
		if(ant.getHealth()) {
			//System.out.println("ant painted");
			Point coord = ant.getCoord();
			int angle = ant.getAngle();
			//AffineTransform affineTransform = new AffineTransform();
			Point c = GamePanel.calculate(coord);
			//affineTransform.translate((c.x-10), (c.y-10));
			//affineTransform.rotate(Math.toRadians(angle*60 + 180), 5, 5);
			switch (angle){
			case 0:
				g.drawImage(antImage0, c.x, c.y, null);
				break;
			case 1:
				g.drawImage(antImage1, c.x, c.y, null);
				break;
			case 2:
				g.drawImage(antImage2, c.x, c.y, null);
				break;
			case 3:
				g.drawImage(antImage3, c.x, c.y, null);
				break;
			case 4:
				g.drawImage(antImage4, c.x, c.y, null);
				break;
			case 5:
				g.drawImage(antImage5, c.x, c.y, null);
				break;
			}
			return true;
		}
		return false;
		
	}

}
